import mcApi from 'mc-c2b2m-operator-api';
import { BasicColumn, FormSchema } from '@/components/Table';
import { SpuCategoryModel } from 'mc-c2b2m-operator-api/types/spu';

const { SpuModule, SysModule } = mcApi;
const { CategoryApi } = SpuModule;
const { UploadApi } = SysModule;

export const tableColumns: BasicColumn[] = [
  { title: '序号', dataIndex: 'sortNo' },
  { title: '编号', dataIndex: 'id' },
  { title: '名称', dataIndex: 'name' },
  {
    title: '分类名称',
    dataIndex: 'categoryList',
    customRender: ({ text }) => {
      return text?.map?.((item: SpuCategoryModel) => item.name)?.join?.('、');
    },
  },
  { title: '示例图', dataIndex: 'imgList', slots: { customRender: 'imgList' } },
  { title: '状态', dataIndex: 'status', slots: { customRender: 'status' } },
  { title: '创建时间', dataIndex: 'createdTime' },
];
export const tableFormSchema: FormSchema[] = [
  {
    field: 'searchContent',
    label: '关键字',
    component: 'Input',
    colProps: { span: 6 },
  },
];

export const modalFormSchema: FormSchema[] = [
  {
    field: 'id',
    label: '编号',
    ifShow: false,
    component: 'Input',
  },
  {
    required: true,
    field: 'categoryId',
    label: '所属大类',
    component: 'ApiSelect',
    componentProps: {
      valueField: 'id',
      labelField: 'name',
      resultField: 'items',
      api: CategoryApi.getSpuCategoryPage,
    },
  },
  {
    required: true,
    field: 'name',
    label: '盒型名称',
    component: 'Input',
  },
  {
    required: true,
    field: 'sortNo',
    label: '序号',
    component: 'InputNumber',
  },
  {
    required: true,
    field: 'imgList',
    label: '示例图',
    component: 'Upload',
    componentProps: {
      api: UploadApi.uploadFile,
      maxNumber: 10,
    },
  },
];
